<template>
  <el-table :data="store.getters['user/getUser']" border style="width: 100%" >
    <el-table-column prop="uid" label="用户编号" />
    <el-table-column prop="username" label="用户名称" />
    <el-table-column prop="rolename" label="所属角色" />
    <el-table-column label="状态">
      <template v-slot="item">
        <el-tag type="success" size="large" plain v-if="(item.row.status == 1)">启用</el-tag>
        <el-tag type="warning" size="large" plain v-else>禁用</el-tag>
      </template>
    </el-table-column>

    <el-table-column label="操作" width="200px">
      <template v-slot="item">
        <el-button type="primary" @click="edit(item.row.uid)">编辑</el-button>
        <el-button type="danger" @click="del(item.row.uid)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination background layout="prev, pager, next" 
  :total="store.getters['user/getCount']"
    :page-size="store.getters['user/getSize']" @current-change="change" />
</template>

  
<script lang="ts" setup>
import { userdelete } from '@/request/api';
import { useStore } from 'vuex';
import {ElMessageBox,ElMessage} from "element-plus"
import { defineEmits } from 'vue';

let emit = defineEmits(["edit"])
let store = useStore()

let edit = (uid: number) => {
  emit("edit",uid)
}

let del = (uid: number) => {
  
  ElMessageBox.confirm(
    '删除后不可恢复，是否确认删除？',
    {
      confirmButtonText: '删除',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
      userdelete({uid}).then(res => {
        console.log(res);
        
        if (res.code == 200) {
          get()
          ElMessage({
            type: 'success',
            message: '删除成功！',
          })
        }
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '取消删除！',
      })
    })
}

let get = () =>{
  store.dispatch('user/getUserAction')  
  store.dispatch('user/getUserCount')
}
get()

let change = (e:any) =>{
  store.dispatch('user/changePageActions',e)
}







</script>